package com.kgc.itrip.controller;

import com.alibaba.fastjson.JSONArray;
import com.kgc.itrip.common.Constants;
import com.kgc.itrip.common.DtoUtil;
import com.kgc.itrip.common.EmptyUtils;
import com.kgc.itrip.common.Page;
import com.kgc.itrip.component.SystemConfig;
import com.kgc.itrip.component.ValidationToken;
import com.kgc.itrip.dto.Dto;
import com.kgc.itrip.pojo.*;
import com.kgc.itrip.service.ItripHotelOrderService;
import com.kgc.itrip.service.ItripHotelRoomService;
import com.kgc.itrip.service.ItripHotelService;
import com.kgc.itrip.service.ItripOrderLinkUserService;
import com.kgc.itrip.vo.order.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 酒店订单的控制器*/
@Api(value = "酒店订单的控制器")
@Slf4j
@RestController
@RequestMapping("/api/hotelorder")
public class HotelOrderController {
    @Resource
    private ValidationToken validationToken;
    @Resource
    private ItripHotelOrderService itripHotelOrderService;
    @Resource
    private ItripHotelService itripHotelService;
    @Resource
    private ItripHotelRoomService itripHotelRoomService;
    @Resource
    private SystemConfig systemConfig;
    @Resource
    private ItripOrderLinkUserService itripOrderLinkUserService;


    @ApiOperation(value = "支付成功后查询订单信息",
            httpMethod = "POST",notes = " success = ‘true’ | 失败：success = ‘false’ " +
            "并返回错误码，如下：错误码:" +
            "100520 : id不能为空"+
            "100519 : 获取数据失败"+
            "100000 : token失效，请重登录",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @PostMapping(value= "/querysuccessorderinfo/{id}")
    public Dto<Map<String,Object>> querysuccessorderinfo(@ApiParam(value = "订单id",required = true,name = "id")
            @PathVariable Integer id,HttpServletRequest request){

            if(id==null || id==0){
                return DtoUtil.returnFail("id不能为空","100520");

            }
            //返回的map集合中的key值是flag,和前端已经约定好了的
            //要验证用户登录先要获取token，user-agent
            //1.获取token
            String token = request.getHeader("token");
            //2.获取user-agent
            String agent = request.getHeader("User-Agent");
            //3.验证用户是否登录
            boolean validate = validationToken.validate(agent,token);
            if (!validate){//说明没有登录
                return DtoUtil.returnFail("token失败，请重新登录","100000");
            }
        try {
            ItripHotelOrder itripHotelOrder = itripHotelOrderService.getItripHotelOrderById(id.longValue());
            if(EmptyUtils.isEmpty(itripHotelOrder)){
                return DtoUtil.returnFail("获取数据失败","100519");
            }
            //根据房间编号查询房间
            Long roomId = itripHotelOrder.getRoomId();
            ItripHotelRoom itripHotelRoom = itripHotelRoomService.getItripHotelRoomById(roomId);
            Map<String,Object> result = new HashMap<>();
            result.put("id",itripHotelOrder.getId());
            result.put("orderNo",itripHotelOrder.getOrderNo());
            result.put("payType",itripHotelOrder.getPayType());
            result.put("payAmount",itripHotelOrder.getPayAmount());
            result.put("hotelkName",itripHotelOrder.getHotelName());
            result.put("roomTitle",itripHotelRoom.getRoomTitle());
            return DtoUtil.returnSuccess("获取数据成功",result);
        }catch (Exception e){
            e.printStackTrace();
            log.error("系统异常:系统异常");
            return DtoUtil.returnFail("系统异常","100534");
        }
    }
    @ApiOperation(value = "根据订单ID查看个人订单详情",
            httpMethod = "POST",notes = "订单状态(0：待支付 2:支付成功 3:已消费 4:已点评)的流程：" +
            "{\"1\":\"订单提交\",\"2\":\"订单支付\",\"3\":\"支付成功\",\"4\":\"入住\",\"5\":\"订单点评\",\"6\":\"订单完成\"}\n" +
            "订单状态(1:已取消)的流程：{\"1\":\"订单提交\",\"2\":\"订单支付\",\"3\":\"订单取消\"}\n" +
            "支持支付类型(roomPayType)：{\"1\":\"在线付\",\"2\":\"线下付\",\"3\":\"不限\"} " +
            "success = ‘true’ | 失败：success = ‘false’ " +
            "并返回错误码，如下：错误码:" +
            "100501 : 请传递参数：orderType"+
            "100502 : 请传递参数：orderStatus"+
            "100503 : 获取个人订单列表错误"+
            "100000 : token失效，请重登录",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @PostMapping(value= "getpersonalorderlist")
    public Dto<Page<ItripListHotelOrderVO>> getPersonalOrderList(@RequestBody ItripSearchOrderVO itripSearchOrderVO,HttpServletRequest request){
        try {
            //返回的map集合中的key值是flag,和前端已经约定好了的
            //要验证用户登录先要获取token，user-agent
            //1.获取token
            String token = request.getHeader("token");
            //2.获取user-agent
            String agent = request.getHeader("User-Agent");
            //3.验证用户是否登录
            boolean validate = validationToken.validate(agent,token);
            if (!validate){//说明没有登录
                return DtoUtil.returnFail("token失败，请重新登录","100000");
            }
            if(itripSearchOrderVO.getOrderType()==null || itripSearchOrderVO.getOrderType()==0){
                return DtoUtil.returnFail("请传递参数：orderType","100501");

            }
            if(itripSearchOrderVO.getOrderStatus()==null){
                return DtoUtil.returnFail("请传递参数：orderStatus","100502");
            }
            ItripUser itripUser = validationToken.getCurrentUser(token);
            Map<String,Object> params = new HashMap<>();
            params.put("userId",itripUser.getId());
            params.put("linkUserName",itripSearchOrderVO.getLinkUserName());
            params.put("orderNo",itripSearchOrderVO.getOrderNo());
            params.put("orderType",itripSearchOrderVO.getOrderType()== -1 ? null : itripSearchOrderVO.getOrderType());
            params.put("orderStatus",itripSearchOrderVO.getOrderStatus()== -1 ? null : itripSearchOrderVO.getOrderStatus());
            params.put("startDate",itripSearchOrderVO.getStartDate());
            params.put("endDate",itripSearchOrderVO.getStartDate());
            Page<ItripListHotelOrderVO> Page = itripHotelOrderService.queryItripHotelOrderPageByMap(params, itripSearchOrderVO.getPageNo(), itripSearchOrderVO.getPageSize());
            return DtoUtil.returnDataSuccess(Page);
        }catch (Exception e){
            e.printStackTrace();
            log.error("获取个人订单信息错误 ");
            return DtoUtil.returnFail("获取个人订单列表错误","100503");
        }
    }

    @ApiOperation(value = "修改订单的支付方式和状态",
            httpMethod = "POST",notes = " success = ‘true’ | 失败：success = ‘false’ " +
            "并返回错误码，如下：错误码:" +
            "100521 : 对不起，此房间不支持线下支付"+
            "100522 : 修改订单失败"+
            "100523 : 不能提交空，请填写订单信息 "+
            "100000 : token失效，请重登录",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @PostMapping(value= "/updateorderstatusandpaytype")
    public Dto<Object> getPersonalOrderRoomInfo(@RequestBody ItripModifyHotelOrderVO itripModifyHotelOrderVO,HttpServletRequest request){
        try {
            if(EmptyUtils.isEmpty(itripModifyHotelOrderVO)
            || itripModifyHotelOrderVO.getId()==null||itripModifyHotelOrderVO.getId()==0
            ||itripModifyHotelOrderVO.getPayType()==null){
                return DtoUtil.returnFail("不能提交空，请填写订单信息","100523");

            }
            //返回的map集合中的key值是flag,和前端已经约定好了的
            //要验证用户登录先要获取token，user-agent
            //1.获取token
            String token = request.getHeader("token");
            //2.获取user-agent
            String agent = request.getHeader("User-Agent");
            //3.验证用户是否登录
            boolean validate = validationToken.validate(agent,token);
            if (!validate){//说明没有登录
                return DtoUtil.returnFail("token失败，请重新登录","100000");
            }
            //根据线下订单编号调用业务逻辑层查询是否支持线下支付
            boolean isSupportOffLinePayType = itripHotelOrderService.getIsSupportOffLinePayByOrderId(itripModifyHotelOrderVO.getId());
            if(!isSupportOffLinePayType){
                return DtoUtil.returnFail("对不起此房间不支持线下支付","100521");
            }
            //如果代码能走到这里，就去修改订单支付状态

            ItripUser currentUser = validationToken.getCurrentUser(token);
            boolean isSuccess = itripHotelOrderService.itriptxModifyItripHotelOrder(itripModifyHotelOrderVO, currentUser);
            if(!isSuccess){
                return DtoUtil.returnFail("修改订单失败","100522");
            }
            return DtoUtil.returnDataSuccess("修改订单状态和支付方式成功！");
        }catch (Exception e){
            e.printStackTrace();
            log.error("系统异常:系统异常");
            return DtoUtil.returnFail("系统异常","100534");
        }
    }




    @ApiOperation(value = "根据订单ID查看个人订单详情-房型相关信息",
            httpMethod = "GET",notes = " success = ‘true’ | 失败：success = ‘false’ " +
            "并返回错误码，如下：错误码:" +
            "100529 : 请传递参数：orderId"+
            "100530 : 没有相关订单房型信息"+
            "100531 : 获取个人订单房型信息错误"+
            "100000 : token失效，请重登录",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @GetMapping(value= "/getpersonalorderroominfo/{orderId}")
    public Dto<ItripPersonalOrderRoomVO> getPersonalOrderRoomInfo(@ApiParam(value = "订单Id",required = true)
                                                            @PathVariable String orderId , HttpServletRequest request){
        try {
            if(EmptyUtils.isEmpty(orderId)){
                return DtoUtil.returnFail("请传递参数：orderId","100529");

            }
            //返回的map集合中的key值是flag,和前端已经约定好了的
            //要验证用户登录先要获取token，user-agent
            //1.获取token
            String token = request.getHeader("token");
            //2.获取user-agent
            String agent = request.getHeader("User-Agent");
            //3.验证用户是否登录
            boolean validate = validationToken.validate(agent,token);
            if (!validate){//说明没有登录
                return DtoUtil.returnFail("token失败，请重新登录","100000");
            }
            ItripPersonalOrderRoomVO itripPersonalOrderRoomVO = itripHotelOrderService.queryPersonalOrderRoomInfoByOrderId(Long.parseLong(orderId));
            if(EmptyUtils.isEmpty(itripPersonalOrderRoomVO)){
                return DtoUtil.returnFail("没有相关订单房型信息","100530");
            }
            return DtoUtil.returnDataSuccess(itripPersonalOrderRoomVO);
        }catch (Exception e){

            e.printStackTrace();
            log.error("系统异常:系统异常");
            return DtoUtil.returnFail("系统异常","100534");
        }
    }

    @ApiOperation(value = "生成订单",
            httpMethod = "POST",notes = " success = ‘true’ | 失败：success = ‘false’ " +
            "并返回错误码，如下：错误码:" +
            "100505 : 生成订单失败"+
            "100506 : 不能提交空，请填写订单信息"+
            "100507 : 库存不足"+
            "100000 : token失效，请重登录",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @PostMapping(value= "/addhotelorder")
    public Dto<Map<String,Object>> addHotelOrder(@RequestBody ItripAddHotelOrderVO itripAddHotelOrderVO,
                                                 HttpServletRequest request){
        try {
            //返回的map集合中的key值是flag,和前端已经约定好了的
            //要验证用户登录先要获取token，user-agent
            //1.获取token
            String token = request.getHeader("token");
            //2.获取user-agent
            String agent = request.getHeader("User-Agent");
            //3.验证用户是否登录
            boolean validate = validationToken.validate(agent,token);
            if (!validate){//说明没有登录
                return DtoUtil.returnFail("token失败，请重新登录","100000");
            }
            if (EmptyUtils.isEmpty(itripAddHotelOrderVO)
                    || itripAddHotelOrderVO.getOrderType()==null
                    || itripAddHotelOrderVO.getHotelId()==0 || itripAddHotelOrderVO.getHotelId()==null
                    || EmptyUtils.isEmpty(itripAddHotelOrderVO.getHotelName())
                    || itripAddHotelOrderVO.getRoomId()==0 || itripAddHotelOrderVO.getRoomId()==null
                    || itripAddHotelOrderVO.getCount()==0 || itripAddHotelOrderVO.getCount()==null
                    || EmptyUtils.isEmpty(itripAddHotelOrderVO.getCheckInDate())
                    || EmptyUtils.isEmpty(itripAddHotelOrderVO.getCheckOutDate())
                    || itripAddHotelOrderVO.getCheckInDate().getTime() > itripAddHotelOrderVO.getCheckOutDate().getTime()
                    || EmptyUtils.isEmpty(itripAddHotelOrderVO.getNoticePhone())
                    || EmptyUtils.isEmpty(itripAddHotelOrderVO.getNoticeEmail())
                    || EmptyUtils.isEmpty(itripAddHotelOrderVO.getLinkUser()) || itripAddHotelOrderVO.getLinkUser().size()==0){
                return DtoUtil.returnFail("不能提交空，请填写订单信息","100506");
            }
            //验证库存是否充足
            Map<String,Object> params = new HashMap<>();
            params.put("hotelId",itripAddHotelOrderVO.getHotelId());
            params.put("roomId",itripAddHotelOrderVO.getRoomId());
            params.put("count",itripAddHotelOrderVO.getCount());
            params.put("checkInDate",itripAddHotelOrderVO.getCheckInDate());
            params.put("checkOutDate",itripAddHotelOrderVO.getCheckOutDate());
            //6.调用业务逻辑层去执行
            boolean flag = itripHotelOrderService.getValidateRoomStore(params);
            if (!flag){
                return DtoUtil.returnFail("库存不足","100507");
            }
            //封装订单信息，调用业务逻辑层去执行保存订单
            ItripUser user = validationToken.getCurrentUser(token);
            Map<String,Object> result = itripHotelOrderService.itriptxCreateItripHotelOrder(itripAddHotelOrderVO,user,token);
            return DtoUtil.returnDataSuccess(result);
        }catch (Exception e){
            e.printStackTrace();
            log.error("系统异常，添加订单失败");
            return DtoUtil.returnFail("生成订单失败","100505");
        }
    }

    @ApiOperation(value = "修改订房日期验证是否有房",
            httpMethod = "POST",
            notes = " success = ‘true’ | 失败：success = ‘false’ 并返回错误码，" +
                    "如下 ：100000 : token失效，请重登录 100515 : hotelId不能为空" +
                    "100516 : roomId不能为空 100517 : 系统异常",
            protocols = "http", produces = "application/json;charset=UTF-8",
            consumes = "application/json")
    @PostMapping(value = "/validateroomstore")
    public Dto<Map<String, Boolean>> ValidateRoomStoreVO(@RequestBody ValidateRoomStoreVO validateRoomStoreVO, HttpServletRequest request) {
        //验证用户是否登录
        //获取token
        String token = request.getHeader("token");
        //后去user-agent
        String agent = request.getHeader("User-Agent");
        //验证用户是否登录
        boolean validate = validationToken.validate(agent, token);
        if (!validate) {
            return DtoUtil.returnFail("token失效，请重登录", "100000");
        }
        //验证参数
        if (validateRoomStoreVO.getHotelId() == null || validateRoomStoreVO.getHotelId() == 0) {
            return DtoUtil.returnFail("hotelId不能为空", "100515");
        }
        if (validateRoomStoreVO.getRoomId() == null || validateRoomStoreVO.getRoomId() == 0) {
            return DtoUtil.returnFail("roomId不能为空", "100516");
        }
        if (validateRoomStoreVO.getCheckInDate() == null || validateRoomStoreVO.getCheckOutDate() == null) {
            return DtoUtil.returnFail("入住日期和退房时间不能为空", "100514");
        }
        if (validateRoomStoreVO.getCheckInDate().getTime() > validateRoomStoreVO.getCheckOutDate().getTime()) {
            return DtoUtil.returnFail("入住日期和退房时间不能为空", "100514");
        }
        try {
            Integer count = (validateRoomStoreVO.getCount()==0 || null==validateRoomStoreVO.getCount())
                    ? 1
                    : validateRoomStoreVO.getCount();
            //封装条件
            Map<String, Object> params = new HashMap<>();
            params.put("hotelId", validateRoomStoreVO.getHotelId());
            params.put("roomId", validateRoomStoreVO.getRoomId());
            params.put("count", count);
            params.put("checkInDate", validateRoomStoreVO.getCheckInDate());
            params.put("checkOutDate", validateRoomStoreVO.getCheckOutDate());

            //调用业务逻辑层
            boolean flag = itripHotelOrderService.getValidateRoomStore(params);
            Map<String, Boolean> result = new HashMap<>();
            result.put("flag", flag);
            return DtoUtil.returnDataSuccess(result); //7.返回查询结果
        } catch (Exception e) {
            e.printStackTrace();
            log.error("系统异常:生成订单前,获取预定信息失败");
            return DtoUtil.returnFail("系统异常", "100513");
        }
    }
    @ApiOperation(value = "生成订单前,获取预定信息",
            httpMethod = "POST",notes = " success = ‘true’ | 失败：success = ‘false’ " +
            "并返回错误码，如下：错误码:" +
            "100000 : token失效，请重登录," +
            " 100515 : hotelId不能为空, " +
            "100516 : roomId不能为空," +
            "100517 : 系统异常",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @PostMapping(value= "/getpreorderinfo")
    public Dto<RoomStoreVO> getPreOrderInfo(@RequestBody ValidateRoomStoreVO validateRoomStoreVO,
                                            HttpServletRequest request){
        //要验证用户登录先要获取token，user-agent
        //1.获取token
        String token = request.getHeader("token");
        //2.获取user-agent
        String agent = request.getHeader("User-Agent");
        //3.验证用户是否登录
        boolean validate = validationToken.validate(agent,token);
        if (!validate){//说明没有登录
            return DtoUtil.returnFail("token失败，请重新登录","100000");
        }
        //4.验证查询参数
        if (validateRoomStoreVO.getHotelId()==null || validateRoomStoreVO.getHotelId()==0){
            return DtoUtil.returnFail("hotelId不能为空","100510");
        }
        if (validateRoomStoreVO.getRoomId()==null || validateRoomStoreVO.getRoomId()==0){
            return DtoUtil.returnFail("roomId不能为空","100511");
        }
        if (validateRoomStoreVO.getCheckInDate()==null || validateRoomStoreVO.getCheckOutDate()==null){
            return DtoUtil.returnFail("入住日期和退房日期不能为空","100514");
        }
        if (validateRoomStoreVO.getCheckInDate().getTime() > validateRoomStoreVO.getCheckOutDate().getTime()){
            return DtoUtil.returnFail("入住时间不能大于退房时间","100514");
        }
        try {
            Integer count = (validateRoomStoreVO.getCount()==0 || null==validateRoomStoreVO.getCount())
                    ? 1
                    : validateRoomStoreVO.getCount();
            //5.封装查询条件
            Map<String,Object> params = new HashMap<>();
            params.put("hotelId",validateRoomStoreVO.getHotelId());
            params.put("roomId",validateRoomStoreVO.getRoomId());
            //params.put("count",(validateRoomStoreVO.getCount()==0 || null==validateRoomStoreVO.getCount())?1: validateRoomStoreVO.getCount());
            params.put("checkInDate",validateRoomStoreVO.getCheckInDate());
            params.put("checkOutDate",validateRoomStoreVO.getCheckOutDate());
            //6.调用业务逻辑层去执行
            Integer storeMinCount = itripHotelOrderService.getHotelRoomStoreByCondition(params);
            if (count>storeMinCount){
                return DtoUtil.returnFail("暂时无房","100512");
            }
            //封装返回对象
            RoomStoreVO roomStoreVO = new RoomStoreVO();
            roomStoreVO.setHotelId(validateRoomStoreVO.getHotelId());
            roomStoreVO.setRoomId(validateRoomStoreVO.getRoomId());
            roomStoreVO.setCheckInDate(validateRoomStoreVO.getCheckInDate());
            roomStoreVO.setCheckOutDate(validateRoomStoreVO.getCheckOutDate());
            roomStoreVO.setCount(1);
            roomStoreVO.setStore(storeMinCount);
            ItripHotel itripHotel = itripHotelService.getItripHotelById(validateRoomStoreVO.getHotelId());
            roomStoreVO.setHotelName(itripHotel.getHotelName());
            ItripHotelRoom itripHotelRoom = itripHotelRoomService.getItripHotelRoomById(validateRoomStoreVO.getRoomId());
            roomStoreVO.setPrice(BigDecimal.valueOf(itripHotelRoom.getRoomPrice()));
            return DtoUtil.returnDataSuccess(roomStoreVO); //7.返回查询结果
        }catch (Exception e){
            e.printStackTrace();
            log.error("系统异常:生成订单前,获取预定信息失败");
            return DtoUtil.returnFail("系统异常","100513");
        }
    }
    @ApiOperation(value = "根据订单ID查看个人订单详情",
            httpMethod = "GET",notes = " success = ‘true’ | 失败：success = ‘false’ " +
            "订单状态(orderStatus)（0：待支付 1:已取消 2:支付成功 3:已消费 4：已点评）"+
            "并返回错误码，如下：错误码:" +
            "100000 : token失效，请重登录," +
            "100525 : 请传递参数：orderId " +
            "100526 : 没有相关订单信息" +
            "100527 : 获取个人订单信息错误"+
            "100517 : 系统异常",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @GetMapping(value= "/getpersonalorderinfo/{orderId}")
    public Dto<ItripPersonalHotelOrderVO> getPerSonalOrderInfo(@PathVariable String orderId,
                                                               HttpServletRequest request){

        try{
            if(EmptyUtils.isEmpty(orderId)){
                return DtoUtil.returnFail("请传递参数：orderId","100525");
            }
            //要验证用户登录先要获取token，user-agent
            //1.获取token
            String token = request.getHeader("token");
            //2.获取user-agent
            String agent = request.getHeader("User-Agent");
            //3.验证用户是否登录
            boolean validate = validationToken.validate(agent,token);
            if (!validate){//说明没有登录
                return DtoUtil.returnFail("token失败，请重新登录","100000");
            }
            Long oId = Long.parseLong(orderId);
            //更具订单编号查询订单信息
            ItripHotelOrder itripHotelOrder = itripHotelOrderService.getItripHotelOrderById(oId);
            if(itripHotelOrder==null){
                return DtoUtil.returnFail("没有相关订单信息","100526");
            }
            ItripPersonalHotelOrderVO hotelOrderVO = new ItripPersonalHotelOrderVO();
            BeanUtils.copyProperties(itripHotelOrder,hotelOrderVO);
            ItripHotelRoom itripHotelRoom = itripHotelRoomService.getItripHotelRoomById(itripHotelOrder.getRoomId());
            hotelOrderVO.setPayType(itripHotelRoom.getPayType());
            hotelOrderVO.setPayAmount(BigDecimal.valueOf(itripHotelOrder.getPayAmount()));
            if(itripHotelOrder.getOrderStatus()== Constants.ORDER_STATUS.TO_PAY){//待支付
                hotelOrderVO.setOrderProcess(JSONArray.parse(systemConfig.getOrderProcessOK()));
                hotelOrderVO.setProcessNode("2");
            }else if (itripHotelOrder.getOrderStatus()== Constants.ORDER_STATUS.CANCEL){//取消
                hotelOrderVO.setOrderProcess(JSONArray.parse(systemConfig.getOrderProcessCancel()));
                hotelOrderVO.setProcessNode("3");
            }else if (itripHotelOrder.getOrderStatus()== Constants.ORDER_STATUS.PAY_SUCCESS){//支付成功
                hotelOrderVO.setOrderProcess(JSONArray.parse(systemConfig.getOrderProcessOK()));
                hotelOrderVO.setProcessNode("3");
            }else if (itripHotelOrder.getOrderStatus()== Constants.ORDER_STATUS.CONSUMED){//以消费
                hotelOrderVO.setOrderProcess(JSONArray.parse(systemConfig.getOrderProcessOK()));
                hotelOrderVO.setProcessNode("3");
            }else if (itripHotelOrder.getOrderStatus()== Constants.ORDER_STATUS.COMMENTED){//评论
                hotelOrderVO.setOrderProcess(JSONArray.parse(systemConfig.getOrderProcessOK()));
                hotelOrderVO.setProcessNode("3");
            }else {//其他情况
                hotelOrderVO.setOrderProcess(null);
                hotelOrderVO.setProcessNode(null);
            }
            return DtoUtil.returnDataSuccess(hotelOrderVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error("系统异常：获取个人订单信息错误");
            return DtoUtil.returnFail("获取个人订单信息错误","100527");
        }
    }
    @ApiOperation(value = "根据订单ID获取订单信息",
            httpMethod = "GET",notes = " success = ‘true’ | 失败：success = ‘false’ " +
            "并返回错误码，如下：错误码:" +
            "没有查询到相应订单 : 没有查询到相应订单" +
            "100534 : 系统异常",
            protocols = "http",
            produces = "application/json",
            consumes = "application/json")
    @GetMapping(value= "/queryOrderById/{orderId}")
    public Dto<ItripModifyHotelOrderVO> queryOrderById(@PathVariable Long orderId,HttpServletRequest request){
        try{
            //要验证用户登录先要获取token，user-agent
            //1.获取token
            String token = request.getHeader("token");
            //2.获取user-agent
            String agent = request.getHeader("User-Agent");
            //3.验证用户是否登录
            boolean validate = validationToken.validate(agent,token);
            if (!validate){//说明没有登录
                return DtoUtil.returnFail("token失败，请重新登录","100000");
            }
           //根据订单编号调用业务逻辑层查询数据
            ItripHotelOrder itripHotelOrder = itripHotelOrderService.getItripHotelOrderById(orderId);
            if(EmptyUtils.isEmpty(itripHotelOrder)){
                return DtoUtil.returnFail("没有查询到相应订单","没有查询到相应订单");
            }
            ItripModifyHotelOrderVO itripModifyHotelOrderVO = new ItripModifyHotelOrderVO();
            BeanUtils.copyProperties(itripHotelOrder,itripModifyHotelOrderVO);
            Map<String,Object> parmas = new HashMap<>();
            parmas.put("orderId",itripHotelOrder.getId());
            List<ItripOrderLinkUser> linkUserList = itripOrderLinkUserService.getItripOrderLinkUserListByMap(parmas);
            List<ItripOrderLinkUserVo> linkUserVoList = null;
            if(EmptyUtils.isNotEmpty(linkUserList)){
                linkUserVoList = new ArrayList<>();
                for (ItripOrderLinkUser orderLinkUser : linkUserList) {
                    ItripOrderLinkUserVo linkUserVo = new ItripOrderLinkUserVo();
                    BeanUtils.copyProperties(orderLinkUser,linkUserVo);
                    linkUserVoList.add(linkUserVo);
                }
            }
            if(EmptyUtils.isNotEmpty(linkUserVoList)){
                itripModifyHotelOrderVO.setItripOrderLinkUserList(linkUserVoList);
            }
            return DtoUtil.returnDataSuccess(itripModifyHotelOrderVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error("系统异常");
            return DtoUtil.returnFail("系统异常","100534");
        }
    }
}